package com.swipemaster.elements;

import android.graphics.Canvas;

import com.swipemaster.moves.FreeMove;
import com.swipemaster.moves.Move;

/** A class describing primitive elements appearing on the screen. */
abstract public class Element
{
	/** Position of the center of element in px. */
	public int x, y;
	/** Type of move. */
	public final Move move;
	/** Mass used in bouncing. */
	public final double mass;

	/** @param x X center in px.
	 * @param y Y center in px.
	 * @param move Type of move.
	 * @param mass Mass of element. */
	public Element(int x, int y, Move move, double mass)
	{
		this.x = x;
		this.y = y;
		this.move = move;
		this.mass = mass;
	}

	public void bounceWith(Element element)
	{
		if (move instanceof FreeMove)
		{
			final FreeMove freeMove = (FreeMove) move;
			freeMove.bounce(this, element);
		}
	}

	abstract public void draw(Canvas canvas);

	/** @return True, if there is a collision between this and given element. */
	abstract public boolean isCollisionWith(Element element);

	/** @return True, if there is a collision between this element and certain wall, given as parameter. */
	abstract public boolean isWallCollision(int wall, boolean wallCollision);

	/** Called periodically in order to move element. */
	public void move(int interval)
	{
		move.calculateNextPosition(this, interval);
		x = move.nextX;
		y = move.nextY;
	}

	public void speedUp(double scale)
	{
		move.speedUp(scale);
	}
}
